home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-11-12 | 3.2 KB | 124 lines | [TEXT/PJMM] |
- program DialogDemo;
-
- uses
- Memtypes, Quickdraw, OSIntf, ToolIntf, PackIntf, SANE, DialogHandlerHeader;
-
- const
- DLog_ID = 10000;
- DLogGotIt = 1;
- DLogDone = 2;
- DLogQUESTION = 3;
- DLogANSWER = 4;
- DLogPickUserItem = 5;
- DLogUpdateUserItem = 6;
- DLogComment = 7;
-
- CapitalListStrings = 1570;
- CapitalStrings = 9042;
- StateStrings = 2460;
- numberofallstates = 50;
-
- var
- stateindex, capitalindex: integer;
- Capital: array[1..50] of integer;
- Radiobuttonstatus: integer;
- set1: RadioButtonSetPtr;
- stcap, cities: str255;
- currentstate: str255;
-
- function rand (limit: integer): integer; {returns a random number between 1 and limit}
-
- var
- secs, x: longint;
- begin
- GetDateTime(secs);
- randseed := secs;
- x := abs(random);
- while x >= limit do
- begin
- x := x div 10;
- end;
- x := x + 1;
- rand := x;
- end;
-
- procedure Mystartproc (dp: DialogPtr; itemHit: Integer; doubleclick: boolean; PickHandle: Listhandle; dhp: DialogHandlerRecordPtr);
- var
- i: integer;
- Selectresult: boolean;
- itemtype, ans: integer;
- itemHandle: Handle;
- itemRect: rect;
-
- begin
- Stateindex := rand(numberofallstates);
- GetIndString(currentstate, StateStrings, Stateindex);
- PickHandle := DHGetPickListHandle(dhp, DLogPickUserItem);
- DHEmptyPickList(PickHandle);
- DHAddPickListStringList(PickHandle, CapitalListStrings);
- DHAddStaticString(dhp, DLogQuestion, currentState);
- GetDItem(dp, DLogQuestion, itemType, itemHandle, itemRect);
- SetIText(itemHandle, currentState);
- end;
-
- procedure GotIt (dp: DialogPtr; itemHit: Integer; dhp: DialogHandlerRecordPtr);
- var
- PickHandle: Listhandle;
- Selectresult: boolean;
- itemtype, ans: integer;
- itemHandle: Handle;
- itemRect: rect;
-
- begin
- PickHandle := DHGetPickListHandle(dhp, DLogPickUserItem);
- Selectresult := DHIsPickListItemSelected(PickHandle, capital[stateindex] - 1);
- if Selectresult then
- begin {correct answer!}
- GetDItem(dp, DLogComment, itemType, itemHandle, itemRect);
- SetIText(itemHandle, 'Last Selection was correct!');
- MyStartProc(dp, itemHit, false, PickHandle, dhp);
- end
- else
- begin {wrong answer}
- GetDItem(dp, DLogComment, itemType, itemHandle, itemRect);
- SetIText(itemHandle, 'Last Selection was wrong!');
- end;
-
- end;
-
- procedure DoThatDialog;
- var
- dhp: DialogHandlerRecordPtr;
- i, offset: integer;
- begin
- DHNewRecord(dhp, DLog_ID, DefaultItem, DLogUpdateUserItem, NoCancelItem, NoSelectedItem);
- DHShowArrowCursor;
- DHAddPushButton(dhp, DLogDone, Exit);
- DHAdvAddPushButton(dhp, DLogGotIt, NoExit, DHNoKeyEquiv, @GotIt);
- DHAddPickList(dhp, DLogPickUserItem, @MyStartProc);
- for i := 1 to 50 do
- begin
- GetIndString(stcap, CapitalStrings, i);
- offset := 0;
- repeat
- begin
- offset := offset + 1;
- GetIndString(cities, CapitalListStrings, offset);
- end;
- until stcap = cities;
- capital[i] := offset;
- end;
- Stateindex := rand(numberofallstates);
- GetIndString(currentstate, StateStrings, Stateindex);
- DHAddStaticString(dhp, DLogQuestion, currentState);
- DHSetCentering(dhp, True, True, SaveCenteringOff);
- if DHDialogHandler(dhp) then
- begin {user hit the OK}
- {End the program}
- end;
- DHDeallocateRecord(dhp);
- end;
-
- begin
- DoThatDialog;
- end.